package com.ls.pattern.behavior.interpreter;


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;

public class Main {
    public static void main(String[] args) throws Exception {
        String expStr = getExpStr();
        HashMap<String, Integer> var = getValue(expStr);
        Calculator calculator = new Calculator(expStr);
        System.out.println(calculator.run(var));
    }

    private static HashMap<String, Integer> getValue(String expStr) throws Exception {
        HashMap<String, Integer> map = new HashMap<>();
        for (char ch : expStr.toCharArray()) {
            if (ch != '+' && ch != '-') {
                if (!map.containsKey(String.valueOf(ch))) {
                    System.out.println("请输入" + ch + "的值");
                    String in = new BufferedReader(new InputStreamReader(System.in)).readLine();
                    map.put(ch + "", Integer.valueOf(in));

                }
            }
        }
        return map;
    }

    private static String getExpStr() throws Exception {
        System.out.println("请输入表达式:");
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        return bufferedReader.readLine();
    }

}
